
package com.ukao.pad.presenter;

import com.ukao.pad.base.BasePresenter;
import com.ukao.pad.bean.AccountLoginBean;
import com.ukao.pad.bean.TokenBean;
import com.ukao.pad.consts.Constant;
import com.ukao.pad.consts.SaveParamets;
import com.ukao.pad.retrofit.ApiCallback;
import com.ukao.pad.utils.CipherUtils;
import com.ukao.pad.utils.Utils;
import com.ukao.pad.view.loginView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class LoginPesenter extends BasePresenter<loginView> {



    public LoginPesenter(loginView view) {
        attachView(view);
    }






    public void appSecretData(     ) {

        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        addSubscription(apiStores.getToken(Constant.firstParameter(mHashMap)),
                new ApiCallback<TokenBean>() {
                    @Override
                    public void onSuccess(TokenBean model) {

                        if (model.getHttpCode() == 200) {

                            mvpView.appSecretSucceed(model.getData().getAppSecret());
                        }else{

                            mvpView.loadFailure(model.getMsg());
                        }

                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {

                        mvpView.hideLoading();

                    }
                });
    }





    public void loginRequest() {   /*13708007874本地   //12012341234@xxd  */  /**/
        mvpView.showLoading();
        String sign = SaveParamets.getsaveloginSign(Utils.getContext());
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("account","xxdlggc@xxd");
        mHashMap.put("password",CipherUtils.md5(CipherUtils.md5("123123") + sign));
        addSubscription(apiStores.login(Constant.createParameter(mHashMap)),
                new ApiCallback<AccountLoginBean>() {
                    @Override
                    public void onSuccess(AccountLoginBean model) {

                        if (model.getHttpCode() == 200) {
                            AccountLoginBean mitem = model.getData();
                            mvpView.loadloginSucceed(mitem);


                        } else {
                            mvpView.loadFailure(model.getMsg());
                        }
                    }

                    @Override
                    public void onNoNewWork() {

                    }

                    @Override
                    public void onFinish() {

                        mvpView.hideLoading();
                    }


                });
    }



    public void swipingCardlogin(String  rfidSecret  ) {
       // mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("rfidSecret", rfidSecret);
        addSubscription(apiStores.swipingCardlogin(Constant.createParameter(mHashMap)),
                new ApiCallback<AccountLoginBean>() {
                    @Override
                    public void onSuccess(AccountLoginBean model) {

                        if (model.getHttpCode()==200){
                            AccountLoginBean mitem = model.getData();
                            mvpView.loadloginSucceed(mitem);

                        }else{
                            mvpView.loadFailure(model.getMsg());
                        }
                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }
                });
    }





}
